﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Reflection;
using System;


/// <summary>
/// 将field的分类并体现在编辑器上，暂时只对Warrior类实现
/// </summary>
[CustomEditor(typeof(Warrior))]
public class Test_WarriorBattleComponentEditor : Editor {
    public override void OnInspectorGUI()
    {
        Type t = target.GetType();
        var fields = t.GetFields(BindingFlags.Instance | BindingFlags.Public  | BindingFlags.DeclaredOnly);
        

        var centeredStyle = GUI.skin.GetStyle("Label");
        centeredStyle.alignment = TextAnchor.UpperCenter;

        EditorGUILayout.LabelField("-------组件依赖-------", centeredStyle);
        foreach(var field in fields)
        {
            BattleComponentFieldAttr attr = field.GetCustomAttributes(typeof(BattleComponentFieldAttr), false)[0] as BattleComponentFieldAttr;
            if(attr.FieldType== BattleComponentFieldtype.ComponentDependent)
                UnityEditorHelper.DrawFieldOnEditorGUI(field, target);
        }
        EditorGUILayout.LabelField("-------开发期预设字段-------", centeredStyle);
        foreach (var field in fields)
        {
            BattleComponentFieldAttr attr = field.GetCustomAttributes(typeof(BattleComponentFieldAttr), false)[0] as BattleComponentFieldAttr;
            if (attr.FieldType == BattleComponentFieldtype.Preset)
            {
                EditorGUILayout.LabelField(attr.description);
                UnityEditorHelper.DrawFieldOnEditorGUI(field, target);
            }
            
        }


        EditorGUILayout.LabelField("-------战斗稳定字段-------", centeredStyle);
        foreach (var field in fields)
        {
            BattleComponentFieldAttr attr = field.GetCustomAttributes(typeof(BattleComponentFieldAttr), false)[0] as BattleComponentFieldAttr;
            if (attr.FieldType == BattleComponentFieldtype.BattlePersistent)
            {
                EditorGUILayout.LabelField(attr.description);
                UnityEditorHelper.DrawFieldOnEditorGUI(field, target);
            }
                
        }

        EditorGUILayout.LabelField("-------战斗动态字段-------", centeredStyle);
        foreach (var field in fields)
        {
            BattleComponentFieldAttr attr = field.GetCustomAttributes(typeof(BattleComponentFieldAttr), false)[0] as BattleComponentFieldAttr;
            if (attr.FieldType == BattleComponentFieldtype.BattleVolatile)
            {
                EditorGUILayout.LabelField(attr.description);
                UnityEditorHelper.DrawFieldOnEditorGUI(field, target);
            }
        }

        EditorGUILayout.LabelField("-------帧内交流字段-------", centeredStyle);
        foreach (var field in fields)
        {
            BattleComponentFieldAttr attr = field.GetCustomAttributes(typeof(BattleComponentFieldAttr), false)[0] as BattleComponentFieldAttr;
            if (attr.FieldType == BattleComponentFieldtype.InterPhase)
            {
                EditorGUILayout.LabelField(attr.description);
                UnityEditorHelper.DrawFieldOnEditorGUI(field, target);
            }
        }


        //base.OnInspectorGUI();

    }

}
